// pages/registration/affirm/affirm.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userName: '张二胖',
    phone: '18339263333',
    hospital:'白泽第一中心医院',
    type: '普通号',
    money: 10,
    keshi:"",
    haoduan:"",
    isShow: true,
    time: ''
  },

  //加载用户信息
  loadInfo(){
    let userName2 = wx.getStorageSync('userName2');
    let phone2 = wx.getStorageSync('phone2');
    let id = wx.getStorageSync('id2');
    let hospital2 = wx.getStorageSync('hospital');
    let keshi2 = wx.getStorageSync('keshi');
    let type2 = wx.getStorageSync('type');
    let haoduan2 = wx.getStorageSync('haoduan');
    let money2 = wx.getStorageSync('money');
    let time2 = wx.getStorageSync('time');
    this.setData({
      userName: userName2,
      phone: phone2,
      hospital: hospital2,
      keshi: keshi2,
      type: type2,
      haoduan: haoduan2,
      money: money2,
      time: time2
    })
    
    console.log("id:",id);
    console.log(userName2,phone2);

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadInfo();
  },

  //点击提交
  btnClick(){
    let openId = wx.getStorageSync('openId');
    let userName = wx.getStorageSync('userName2');
    let phone = wx.getStorageSync('phone2');
    let id = wx.getStorageSync('id2');
    let idCard = wx.getStorageSync('idCard2')
    let keshi = this.data.keshi;
    let type = this.data.type;
    let haoduan = this.data.haoduan;
    let money = this.data.money;
    let time = this.data.time;
    let departmentId = wx.getStorageSync('departmentId');
    console.log(userName,phone,id,idCard,keshi,type,haoduan,money,time,openId,departmentId);
    wx.setStorageSync("haoduan",this.data.haoduan);
    //访问服务器，将数据操作后存入数据库
    wx.request({
      url: 'http://localhost:8060/registration/insert',
      method: 'POST',
      header: { "content-type": "application/x-www-form-urlencoded" },
      data: 
      {
        openId,
        userName,
        phone,
        id,
        idCard,
        departmentId,
        type,
        haoduan,
        time,
        money,
        keshi
      },
      success(res){
        let result = res.data.insertStatus;
        console.log(result);
        //将挂号结果放在缓存中
        wx.setStorageSync('insertStatus', result);
        wx.showToast({
          title: '加载中',
          icon: 'loading'
        });
        //跳转页面
        wx.navigateTo({
          url: '/pages/registration/hint/hint',
        })

      }  
    })
    
  },
  

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})